package com.suray.rgv60.task;

import com.suray.basic.wcs.path.core.Node;
import com.suray.basic.wcs.utils.LoggerType;
import com.suray.commin.core.utils.UUID;
import com.suray.rgv.util.RgvLogger;
import com.suray.rgv60.util.RgvTaskType;
import com.suray.type.Rgv60TaskStatus;

/**
 * 单次行驶任务信息
 */
public class RgvTaskInfo {
    //指定路径任务编号
    private String rgvTaskNo;

    private Node startNode;
    private Node endNode;

    RgvTaskType taskType;

    private Rgv60TaskStatus taskStatus;

    /**
     * 历史任务状态，防止日志刷屏
     */
    private Rgv60TaskStatus lastTaskStatus;

    private String serialNum;

    protected RgvTaskInfo(Node startNode, Node endNode, String serialNum, RgvTaskType taskType) {
        this.startNode = startNode;
        this.endNode = endNode;
        this.serialNum = serialNum;
        this.taskType = taskType;
        rgvTaskNo = UUID.randomUUID().toString();
    }

    protected RgvTaskInfo(String rgvTaskNo, Node startNode, Node endNode, String serialNum, RgvTaskType taskType) {
        this.startNode = startNode;
        this.endNode = endNode;
        this.serialNum = serialNum;
        this.rgvTaskNo = rgvTaskNo;
        this.taskType = taskType;
    }

    public String getRgvTaskNo() {
        return rgvTaskNo;
    }

    public Node getStartNode() {
        return startNode;
    }

    public Node getEndNode() {
        return endNode;
    }

    public Rgv60TaskStatus getTaskStatus() {
        return taskStatus;
    }

    public void setTaskStatus(Rgv60TaskStatus taskStatus) {
        this.taskStatus = taskStatus;
    }

    /**
     * 状态是否与上次一致
     * @return
     */
    public boolean checkSameStatus() {
        if (lastTaskStatus != null && taskStatus.equals(lastTaskStatus)) {
            return true;
        }

        lastTaskStatus = taskStatus;
        RgvLogger.warn(LoggerType.TASK, null, serialNum, toString() + "任务状态更新为：" + taskStatus,
                this.getClass());

        return false;
    }
    @Override
    public String toString() {
        return "RgvTaskInfo{" +
                "rgvTaskNo='" + rgvTaskNo + '\'' +
                ", startNode=" + (startNode == null ? "" : startNode.print()) +
                ", endNode=" + (endNode == null ? "" : endNode.print()) +
                ", taskStatus=" + taskStatus +
                '}';
    }
}
